<!-- header - 头部区域 -->

<script setup>
import { onMounted } from 'vue';
import HeaderCar from '@/components/LayoutComponents/HeaderCar.vue';
import { useCategoryStore } from '@/stores/useCategoryStore';
// vueUse
import { useScroll } from '@vueuse/core'
const { y } = useScroll(window)

const categoryStore = useCategoryStore();
onMounted(() => categoryStore.getCategory())

</script>

<template>
  <header :class="y > 52 ? 'app-header app-header-sticky' : 'app-header'">
    <div class="container">
      <h1 class="logo">
        <RouterLink to="/">小兔鲜</RouterLink>
      </h1>
      <ul class="app-header-nav">
        <li class="home">
          <RouterLink to="/">首页</RouterLink>
        </li>
        <li class="home" v-for="item in categoryStore.categoryList" :key="item.id">
          <RouterLink active-class="active" :to="'/category/' + item.id">{{ item.name }}</RouterLink>
        </li>
      </ul>
      <div class="search" v-if="y < 52">
        <i class="iconfont icon-search"></i>
        <input type="text" placeholder="搜一搜">
      </div>
      <!-- 头部购物车 -->
      <HeaderCar v-if="y < 52" />

      <div class="right" v-else>
        <RouterLink to="/">品牌</RouterLink>
        <RouterLink to="/">专题</RouterLink>
      </div>
    </div>
  </header>
</template>


<style scoped lang='scss'>
.app-header-sticky {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 999;
  border-bottom: 1px solid #f5f5f5;
  box-shadow: 0px 3px 5px #dfe4ea;
}

.app-header {
  background: #fff;

  .container {
    display: flex;
    align-items: center;
  }

  .logo {
    width: 200px;

    a {
      display: block;
      height: 122px;
      width: 100%;
      text-indent: -9999px;
      background: url('@/assets/images/logo.png') no-repeat center 18px / contain;
    }
  }

  .app-header-nav {
    // width: 820px;
    display: flex;
    padding-left: 40px;
    position: relative;
    z-index: 998;

    li {
      margin-right: 40px;
      width: 38px;
      text-align: center;

      a {
        font-size: 16px;
        line-height: 22px;
        height: 22px;
        display: inline-block;

        &:hover {
          color: $xtxColor;
          border-bottom: 1px solid $xtxColor;
        }
      }

      .active {
        color: $xtxColor;
        border-bottom: 1px solid $xtxColor;
      }
    }
  }

  .search {
    width: 170px;
    height: 22px;
    position: relative;
    border-bottom: 1px solid #e7e7e7;
    line-height: 22px;

    .icon-search {
      font-size: 18px;
      margin-left: 5px;
    }

    input {
      width: 140px;
      padding-left: 5px;
      color: #666;
    }
  }

  .cart {
    width: 50px;

    .curr {
      height: 22px;
      line-height: 22px;
      text-align: center;
      position: relative;
      display: block;

      .icon-cart {
        font-size: 22px;
      }

      em {
        font-style: normal;
        position: absolute;
        right: 0;
        top: 0;
        padding: 1px 6px;
        line-height: 1;
        background: $helpColor;
        color: #fff;
        font-size: 12px;
        border-radius: 10px;
        font-family: Arial;
      }
    }
  }
}

.right {
  width: 220px;
  display: flex;
  text-align: center;
  padding-left: 40px;
  border-left: 2px solid $xtxColor;

  a {
    width: 38px;
    margin-right: 40px;
    font-size: 16px;
    line-height: 1;

    &:hover {
      color: $xtxColor;
    }
  }
}
</style>